<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>3_回调ref回调次数的问题</title>
</head>

<body>
    <!-- 准备好一个容器 -->
    <div id="test"></div>
    <script type="text/javascript" src="../js/react.development.js"></script>
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <script type="text/javascript" src="../js/prop-types.js"></script>
    <script type="text/babel">
        // 创建组件
        class Demo extends React.Component {
            state = {
                isHot: true,
            }
            // 展示左侧输入框的数据
            showData = () => {
                const { value } = this.input1;
                alert(value);
            }
            changeWeather = () => {
                // 获取状态数据
                const { isHot } = this.state;
                // 更新状态数据
                this.setState({ isHot: !isHot })
            }
            saveInput = (node) => {
                this.input1 = node;
                console.log(node);
            }
            // 渲染组件结构
            render() {
                const { isHot } = this.state;
                return (
                    <div>
                        <h1>今天天气{isHot ? '炎热' : '凉爽'}</h1>
                        <input ref={this.saveInput} type="text" />
                        <br />
                        <br />
                        <button onClick={this.showData}>点我提示左侧数据</button>&nbsp;
                        <button onClick={this.changeWeather}>点我切换天气</button>
                    </div>
                )
            }
        }
        // 渲染组件到页面
        ReactDOM.render(<Demo />, document.getElementById("test"));
    </script>
</body>

</html>